package File;
import java.io.*;
import java.util.Date;

public class FileTest {
    public static void main(String[] args)
    {
        try {
            String fileName = "d:\\my-java.txt";
            File myFile = new File(fileName);

            myFile.createNewFile();
            if (myFile.isDirectory()) {
                System.out.println(fileName + "是目录!");
                // 再创建一个目录
                File myData = new File("my-data");
                myData.mkdir();
            }
            if(myFile.isFile())
            {
                System.out.println(fileName + "是文件!");
                System.out.println("文件的绝对路径:>"+myFile.getAbsolutePath());
                System.out.println("文件的大小:>"+myFile.length());
                System.out.println("文件是否能读?"+myFile.canRead());
                if(myFile.canWrite())
                {
                    System.out.println("设置为只读"+myFile.setReadOnly());
                }
                System.out.println("文件是否可写?"+myFile.canWrite());
                Date d = new Date(myFile.lastModified());
                System.out.println("文件上次修改的时间"+d.toString());
            }
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
    }
}